const http = require('http');
const app = http.createServer();

// 加载数据
const data = require('./data/data.json');
const user = require('./data/user.json');
const product = require('./data/product.json');

app.on("request", (req, res) => {

    // 设置响应头
    res.writeHead(200, {
        'Content-Type': 'application/json',
        'Access-Control-Allow-Origin': "*",
        'Access-Control-Allow-Headers': 'Content-Type'
    })

    let url = req.url;

    switch (url) {
        case "/":
            res.end(JSON.stringify(data)); break;
        case "/user":
            res.end(JSON.stringify(user)); break;
        case "/product":
            res.end(JSON.stringify(product)); break;
    }


})


app.listen(3000, () => {
    console.log('server start');
});